jQuery(document).ready(function(){
	//박스 이동(벽돌 쌓기)
	$.fn.myPlugin = function(options) {
		var config = {
			itemSelector : "> div",
			animateSpeed : "400",
			effect : "linear"
		}
		if (options) $.extend(config, options); 
		this.each(function() {
			var Self = $(this),
				Arry = Self.find(config.itemSelector),
				Total = Arry.length,
				StageWidth;

			/* 1단 max639 */
			var boxPosition01 = {
				boxTop1 :"160",boxLeft1 :"0", //start
				boxTop2 :"108",boxLeft2 :"0",
				boxTop3 :"428",boxLeft3 :"0",
				boxTop4 :"748",boxLeft4 :"0",
				boxTop5 :"1068",boxLeft5 :"0", 
				boxTop6 :"1388",boxLeft6 :"0",
				boxTop7 :"1708",boxLeft7 :"0",
				boxTop9 :"2028",boxLeft8 :"0",
				boxTop8 :"2348",boxLeft9 :"0",
				boxTop10 :"2668",boxLeft10 :"0",  
				//boxTop11 :"2700",boxLeft11 :"20", //endArea
				//boxTop12:"2970",boxLeft12 :"20"
			}
			/* 2단 min640 ~ max960 */
			var boxPosition02 = {
				boxTop1 :"460",boxLeft1 :"0",
				boxTop2 :"140",boxLeft2 :"0",
				boxTop3 :"460",boxLeft3 :"0",
				boxTop4 :"460",boxLeft4 :"320",
				boxTop5 :"780",boxLeft5 :"0",
				boxTop6 :"780",boxLeft6 :"320",
				boxTop7 :"1100",boxLeft7 :"0",
				boxTop8 :"1420",boxLeft8 :"0",
				boxTop9 :"1100",boxLeft9 :"320",
				boxTop10 :"1420",boxLeft10 :"320",
				//boxTop11 :"1740",boxLeft11 :"320", //endArea
				//boxTop12:"1890",boxLeft12 :"290"
			}
			/* 3단 min960 ~ max1279 */
			var boxPosition03 = {
				boxTop1 :"140",boxLeft1 :"0",
				boxTop2 :"140",boxLeft2 :"320",
				boxTop3 :"460",boxLeft3 :"0",
				boxTop4 :"460",boxLeft4 :"320",
				boxTop5 :"460",boxLeft5 :"640",
				boxTop6 :"780",boxLeft6 :"0",
				boxTop7 :"780",boxLeft7 :"320",
				boxTop8 :"1100",boxLeft8 :"0",
				boxTop9 :"780",boxLeft9 :"640",
				boxTop10 :"1100",boxLeft10 :"320",
				boxTop11 :"1100",boxLeft11 :"640", //endArea
				//boxTop12 :"1080",boxLeft12 :"560"
			}
			/* 4단 min1280 */
			var boxPosition04 = {
				boxTop1 :"160",boxLeft1 :"0",
				boxTop2 :"160",boxLeft2 :"320",
				boxTop3 :"160",boxLeft3 :"960",
				boxTop4 :"480",boxLeft4 :"0",
				boxTop5 :"480",boxLeft5 :"320",
				boxTop6 :"480",boxLeft6 :"640",
				boxTop7 :"480",boxLeft7 :"960",
				boxTop8 :"800",boxLeft8 :"0",
				boxTop9 :"800",boxLeft9 :"320",
				boxTop10 :"800",boxLeft10 :"640",
				boxTop11 :"800",boxLeft11 :"960", //endArea
				//boxTop12 :"810",boxLeft12 :"560"
			}
			function ini(){ // 설정
				for (var i=0; i<Total; i++ ){
					Arry.eq(i).css({"position" : "absolute", "z-index" : 20 - Number(i)});
				}
				set();
			}
			function set(){ // width 값 설정 * 리사이즈시 이부분 부터 시작
				StageWidth = $(this).width(); 

				if (StageWidth < 639){
					$("#contents").height('2973');
					calculate(1);
				}else if (StageWidth > 640 && StageWidth < 960){
					$("#contents").height('1760');
					calculate(2);
				}else if (StageWidth > 960 && StageWidth < 1280){
					$("#contents").height('1408');
					calculate(3);
				}else if (StageWidth > 1280){
					$("#contents").height('1175');
					calculate(4);
				}else{
				};
			}

			function calculate(sw){ // 계산
				for (var i=0; i<Total; i++ ){
					var boxTop = "boxPosition0"+sw+".boxTop"+(i+1);
					var boxLeft = "boxPosition0"+sw+".boxLeft"+(i+1);
					var y = Number(eval(boxTop));
					var x = Number(eval(boxLeft));
					var speed = Number(eval(config.animateSpeed)) + (i*200);
				
					shot(Arry.eq(i), x, y, speed);
				}
			}
			function shot(obj,x,y,speed){ // 이동
				obj.stop().animate({left:x,top:y}, speed, config.effect)
			}
			$(window).resize(function(e){set()});
			ini();
		});
		return this;
	}
	var options = {
		animateSpeed : "400",
		effect : "linear",
		effect : "easeInOutQuart"
	}
	$('#contents').myPlugin(options);
	
});